---@class Xiangqi.RoomBase : Base.RoomBase
---@field public board integer[][]
local RoomBase = Fk.Base.RoomBase:subclass("Xiangqi.RoomBase")

local Xq = require "packages.chess-games.xiangqi"
local ReqPlayChess = require "packages.chess-games.xiangqi.core.handler.playchess"

function RoomBase:initialize()
  Fk.Base.RoomBase.initialize(self)

  self.board = Xq:createBoard()
  self:addRequestHandler("Xiangqi.PlayChess", ReqPlayChess)
end

function RoomBase:movePieceTo(pieceId, fromX, fromY, x, y)
  local id = self.board[fromY][fromX]
  if id ~= pieceId then return end
  self.board[fromY][fromX] = 0
  self.board[y][x] = pieceId
end

function RoomBase:serialize()
  local o = Fk.Base.RoomBase.serialize(self)
  o.board = self.board
  return o
end

function RoomBase:deserialize(o)
  Fk.Base.RoomBase.deserialize(self, o)
  self.board = o.board
end

return RoomBase
